import DataBase from 'nedb'

const handleCreateIndex = (name, err) => {
    if(err) {
        console.log(`${name} 创建索引失败：`, err);
    } else {
        console.log(`${name} 创建索引成功`)
    }
}
// 创建一个数据库实例，数据存储到 dbfile 文件中
export const userListDB = new DataBase({filename: './nedb/data/userList.db', autoload: true})
userListDB.ensureIndex({ fieldName: 'userId', unique: true }, handleCreateIndex.bind(null, 'userListDB'))

export const roomListDB = new DataBase({filename: './nedb/data/roomList.db', autoload: true})
roomListDB.ensureIndex({ fieldName: 'roomId', unique: true }, handleCreateIndex.bind(null, 'roomListDB'))

export const roomUserDB = new DataBase({filename: './nedb/data/room_user.db', autoload: true})

export const msgListDB = new DataBase({filename: './nedb/data/msgList.db', autoload: true})

export const friendListDB = new DataBase({filename: './nedb/data/friendList.db', autoload: true})
